package com.secxiot.provider.task.dao;

import com.secxiot.provider.task.entity.TaskExecution;
import com.secxiot.provider.task.entity.TaskExecutionExample;
import com.secxiot.provider.task.vo.TaskConfirmStatusVo;
import com.secxiot.provider.task.vo.TaskDisplayVo;
import com.secxiot.provider.task.vo.TaskVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public interface TaskExecutionDao {
    int countByExample(TaskExecutionExample example);

    int deleteByExample(TaskExecutionExample example);

    int deleteByPrimaryKey(Long id);

    int insert(TaskExecution record);

    int insertSelective(TaskExecution record);

    List<TaskExecution> selectByExample(TaskExecutionExample example);

    TaskExecution selectByPrimaryKey(Long id);

    int updateByExampleSelective(@Param("record") TaskExecution record, @Param("example") TaskExecutionExample example);

    int updateByExample(@Param("record") TaskExecution record, @Param("example") TaskExecutionExample example);

    int updateByPrimaryKeySelective(TaskExecution record);

    int updateByPrimaryKey(TaskExecution record);

    int insertBatch(@Param("records") List<TaskExecution> records);

    List<TaskExecution> selectByReceiverIdAndTime(@Param("receiverId") Long receiverId, @Param("startRow") Long startRow,
                                                  @Param("pageSize") Long pageSize, @Param("since") Date since,
                                                  @Param("last") Date last);

    long countByReceiverIdAndTime(@Param("receiverId") Long receiverId, @Param("since") Date since,
                                  @Param("last") Date last);

    List<TaskDisplayVo> getDepartmentList(@Param("deptId") Long deptId, @Param("pageNo") Long pageNo,
                                          @Param("pageSize") Long pageSize);

    /**
     * 获取已接收任务:按任务类型区分
     *
     * @param userId   用户id
     * @param taskType 任务类型
     * @param pageNo   页码
     * @param pageSize 条数
     * @return 已经接收的各种任务类型的列表
     */
    List<TaskDisplayVo> getReceivedList(@Param("userId") Long userId, @Param("taskType") String taskType,
                                        @Param("pageNo") Long pageNo, @Param("pageSize") Long pageSize, @Param("userType") String userType);

    /**
     *  获取最新任务
     * @param userId 用户ID
     * @param taskType 任务类型
     * @return
     */
    TaskDisplayVo getNewestTask(@Param("userId") Long userId, @Param("taskType") String taskType);

    /**
     * 获取未确认数量
     * @param userId 用户ID
     * @return
     */
    List<TaskConfirmStatusVo> getConfirmStatus(@Param("userId") Long userId);

    /**
     *  获取接收者任务
     * @param taskId
     * @param senderId
     * @return
     */
    TaskExecution getTaskExecution(@Param("taskId") Long taskId,@Param("senderId") Long senderId);

    /**
     * 获取未确认或已接诊但未出诊的任务
     * @return
     */
    List<TaskExecution> getTimeSosTask();

    /**
     * 获取对应的sos任务ID
     * @param taskId 出诊任务ID
     * @param userId
     * @return
     */
    Long getSosTaskId(@Param("taskId") Long taskId,@Param("userId") Long userId);

    /**
     * 获取任务
     * @param taskId 任务ID
     * @param taskType 任务类型
     * @return
     */
    List<TaskExecution> getTaskExecutionByParam(@Param("taskId") Long taskId,@Param("taskType") String taskType);

    /**
     * 获取未确认的任务
     * @return
     */
    List<TaskExecution> getTimeTask();

    /**
     * 根据出诊任务获取其他出诊任务
     * @param taskId 任务ID
     * @return
     */
    List<TaskExecution> getTaskExecutionVisit(@Param("taskId") Long taskId);
}